package com.wgj.android.fragment;

import android.app.Dialog;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.jiaai.xui.base.XFragment;
import com.jiaai.xui.utils.imageload.XImage;
import com.jiaai.xui.view.widget.XAlertMsgDialog;
import com.jiaai.xui.view.widget.XToast;
import com.tencent.mm.opensdk.modelmsg.SendAuth;
import com.tencent.mm.opensdk.openapi.WXAPIFactory;
import com.wgj.android.R;
import com.wgj.android.entity.Member;
import com.wgj.android.http.WGJAPI;
import com.wgj.android.ui.activity.LoginActivity;
import com.wgj.android.ui.activity.MyAgencyActivity;
import com.wgj.android.ui.activity.MyInfoActivity;
import com.wgj.android.ui.activity.MyShareActivity;
import com.wgj.android.ui.activity.MyShopStoreActivity;
import com.wgj.android.ui.activity.MyVipActivity;
import com.wgj.android.ui.activity.ShopStoreActivity;
import com.wgj.android.ui.activity.VersionManageActivity;
import com.wgj.android.utils.CacheUtils;
import com.wgj.android.utils.TextViweUtils;
import com.wgj.android.utils.fonat.IconFonat;
import com.wgj.android.web.WGJWebActivity;
import com.wgj.android.web.entity.WebConfig;
import com.wgj.android.wxapi.WXEntryActivity;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by Administrator on 2017/11/3.
 */

public class MyFragment extends XFragment {
    private  Member member;
    @BindView(R.id.avater)
    ImageView avaterImg;
    @BindView(R.id.nickName)
    TextView nickNameTextView;
    @BindView(R.id.mId)
    TextView mIdTextView;


    @BindView(R.id.myVT)
    TextView myVT;

    @BindView(R.id.myeT)
    TextView myeT;

    @BindView(R.id.myqT)
    TextView myqT;

    @BindView(R.id.vT)
    TextView vT;

    @BindView(R.id.aT)
    TextView aT;


    @BindView(R.id.qbI)
    TextView qbI;



    @Override
    public int getLayoutId() {
        return R.layout.my_fragment;
    }

    @Override
    public void initData(Bundle bundle) {

    }

    @Override
    public void initView() {
        ButterKnife.bind(this,getView());
        setIcon();
    }

    public  void setIcon(){
        TextViweUtils.setDrawableLeft(myVT, IconFonat.Icon.icon_haoyouguanli, Color.parseColor("#0066CC"),8);
        TextViweUtils.setDrawableLeft(myeT, IconFonat.Icon.icon_yongjin, Color.parseColor("#CC6666"),8);
        TextViweUtils.setDrawableLeft(myqT, IconFonat.Icon.icon_fenxiang, Color.parseColor("#CC3333"),8);
        TextViweUtils.setDrawableLeft(qbI, IconFonat.Icon.icon_wallet, Color.parseColor("#f4ea2a"),8);
        TextViweUtils.setDrawableLeft(vT, IconFonat.Icon.icon_banben, Color.parseColor("#CC3333"),8);
        TextViweUtils.setDrawableLeft(aT, IconFonat.Icon.icon_guanyu, Color.parseColor("#0066CC"),8);



    }

    @OnClick(R.id.myInfoBut)
    public void onMyinfoButClick  (View view){
        Intent intent =new Intent(getActivity().getApplication(), MyInfoActivity.class);
        startActivity(intent);
    }

    @Override
    public void onResume() {
        super.onResume();
        member= CacheUtils.getMember();
        XImage.getInstance().load(avaterImg,member.getAvater());
        nickNameTextView.setText(member.getM_nick()+"("+member.getCname()+")");
        mIdTextView.setText("ID:"+member.getM_id());
    }

    @OnClick({R.id.myq,R.id.mye,R.id.myV,R.id.qb})
    public void onClick(View view){
        Intent intent=null;
        switch (view.getId()){
            case R.id.myV:
                 intent=new Intent(getActivity().getApplication(), MyVipActivity.class);
                 startActivity(intent);
                break;
            case R.id.mye:
                intent=new Intent(getActivity().getApplication(), WGJWebActivity.class);
                intent.putExtra(WGJWebActivity.WEB_CONFIG,new WebConfig(WGJAPI.BASEURL+"page/owncommission?mId="+member.getM_id(),"我的推广佣金",1));
                startActivity(intent);
                break;
            case R.id.myq:
                 MyShareActivity.openMyShareUI(this.getContext());
                break;
            case R.id.qb:
                intent=new Intent(getActivity().getApplication(), WGJWebActivity.class);
                intent.putExtra(WGJWebActivity.WEB_CONFIG,new WebConfig(WGJAPI.BASEURL+"page/purse?mId="+member.getM_id(),"我的钱包",1));
                startActivity(intent);
                break;

        }
    }
//    @OnClick({R.id.order1,R.id.order2,R.id.order3,R.id.order4})
//    public void showOrderList(View view){
//        switch (view.getId()){
//            case R.id.order1:
//                XToast.warning("功能正在研发中,(>^ω^<)喵");
//                break;
//            case R.id.order2:
//                XToast.warning("功能正在研发中,(>^ω^<)喵");
//                break;
//            case R.id.order3:
//                XToast.warning("功能正在研发中,(>^ω^<)喵");
//                break;
//            case R.id.order4:
//                XToast.warning("功能正在研发中,(>^ω^<)喵");
//                break;
//        }
//    }

    @OnClick(R.id.versionBut)
    public void  onVersionClick(View view){
        Intent intent =new Intent(getContext(), VersionManageActivity.class);
        startActivity(intent);
        /*XHttp.obtain().get(WGJAPI.CHECK_APP_VERSION, null, new HttpCallBack<Version>() {
            @Override
            public void onSuccess(final Version version) {
                int oldVersion= XAppUtils.getVersionCode(getContext());
                if(version.getVersion()>oldVersion){
                    new XAlertMsgDialog(getContext(),version.getChangelog()).setTitle("发现新版本").setPositiveButton("下载").setListener(new XAlertMsgDialog.OnCloseListener() {
                        @Override
                        public void onClick(Dialog dialog, boolean b) {
                            if(b){
                                DownloadAppUtils.downloadForAutoInstall(getContext(),version.getInstallUrl(),"旺旺生活管家app_v"+ version.getVersionShort(),"旺旺管家发现新版本");
                            }

                        }
                    }).show();
                }else {
                    XToast.warning("当前是最新版本");
                }
            }

            @Override
            public void onFailed(int i, String s, boolean b) {

            }
        });*/

    }

    @OnClick(R.id.aboutBut)
    public void onAboutButClick(View view){
        XToast.warning("即将上线");
    }

    @OnClick(R.id.loginOutBut)
    public void onLoginOutBut(View view){
        new XAlertMsgDialog(getContext(),"是否退出当前登录?").setPositiveButton("退出").setNegativeButton("点错了").setListener(new XAlertMsgDialog.OnCloseListener() {
            @Override
            public void onClick(Dialog dialog, boolean b) {
                if(b){
                    //CacheUtils.logout();
                    Intent intent=new Intent(getContext(),LoginActivity.class);
                    startActivity(intent);
                    getActivity().finish();
                }
            }
        }).show();

    }



}
